import tourist from '../src/data/service/tourist.json';
import serviceLog from '../src//data/service/serviceLog.json';
import chatLog from '../src/data/service/chatLog.json';
import fanHouse from '../src/data/loupan/fang_house.json';
import fang_house_sand from '../src/data/loupan/fang_house_sand.json';
import fang_rental from '../src/data/rental/fang_rental.json';
export default {
  'GET /getTourist': (req: any, res: any) => {
    const { search } = req.query;
    if (search) {
      let arr = tourist.data.filter((item: any) => {
        return item.kefu_name.includes(search);
      });
      let count = tourist.count;
      res.send({
        arr,
        count: count,
      });
    } else {
      let arr = tourist.data;
      let count = tourist.count;
      res.send({
        arr,
        count: count,
      });
    }
  },
  'GET /getServiceLog': (req: any, res: any) => {
    const { search } = req.query;
    if (search) {
      let arr = serviceLog.data.filter((item: any) => {
        return item.kefu_name.includes(search);
      });
      let count = serviceLog.count;
      res.send({
        arr,
        count: count,
      });
    } else {
      let arr = serviceLog.data;
      let count = serviceLog.count;
      res.send({
        arr,
        count: count,
      });
    }
  },
  'GET /getChatLog': (req: any, res: any) => {
    const { value } = req.query;
    console.log(req.query);
    if (value) {
      let arr = chatLog.data.filter((item: any) => {
        return item.from_name.includes(value);
      });
      let count = chatLog.count;
      res.send({
        arr,
        count: count,
      });
    } else {
      let arr = chatLog.data;
      let count = chatLog.count;
      res.send({
        arr,
        count: count,
      });
    }
  },
  'GET /getFanHouse': fanHouse,
  'GET /fang_rental': fang_rental,
  'GET /getHouseDetail': (req: any, res: any) => {
    const { id } = req.query;
    let editIndo = fanHouse.data.find((item: any) => {
      if (item.id == id) {
        return item;
      }
    });
    res.send(editIndo);
  },
  'GET /fang_house_sand': fang_house_sand,
  'GET /getRentalDetail': (req: any, res: any) => {
    const { id } = req.query;
    let editIndo = fang_rental.RECORDS.find((item: any) => {
      if (item.id == id) {
        return item;
      }
    });
    res.send(editIndo);
  },
};
